from myApp.models import User
import hashlib
def changePasswordData(userInfo,passwordInfo):
    oldPwd = passwordInfo['oldPassword']
    newPwd = passwordInfo['newPassword']
    checkNewPwd = passwordInfo['checkNewPassword']

    user = User.objects.get(username=userInfo.username)

    md5 = hashlib.md5()
    md5.update(oldPwd.encode())
    oldPwd = md5.hexdigest()

    print(oldPwd,newPwd,checkNewPwd)

    if oldPwd != user.password: return "原始密码错误"
    if newPwd != checkNewPwd: return "二次密码输入错误"

    # 给新密码加密
    md5 = hashlib.md5()
    md5.update(newPwd.encode())
    newPwd = md5.hexdigest()

    # 修改密码
    user.password = newPwd
    user.save()